<template>
  <div>
    <Row style="padding-top: 16px;text-align: left" align="middle" type="flex">
      <i-col span="24" class="y_query_right">
      <DatePicker type="date" placeholder="Select date" style="width: 200px" v-model="tParam.searchParams.date" class="y_condition"></DatePicker>
      <Tooltip content="勾选此项后可以查询全部用户数据，否则只能查询员工个人推广的用户数据。" max-width="260" class="y_condition">
        <Checkbox v-model="tParam.searchParams.isGetAll" class="modal_form_input" v-has=tRole.ANALYSIS_6_101>查询全部</Checkbox>
      </Tooltip>
      <Button type="primary" style="margin-left: 16px" icon="md-search" @click="search" class="y_condition">查询</Button>
      </i-col>
    </Row>

    <!--表格和分页-->
<!--    <Table stripe border ref="userDailyList" :columns="userDailyTable" :data="userDailyList"-->
<!--           class="table_css" no-data-text="暂无数据" @on-sort-change="sortChanged"></Table>-->

    <List border class="data-list">
      <template v-if="userDailyList.length == 0">
        <ListItem class="list-item">
          <div style="width: 100%; text-align: center; color: #ccc;">暂无数据</div>
        </ListItem>
      </template>
      <template v-else>
        <ListItem v-for="(item, index) in userDailyList" :key="index" class="list-item">
          <div class="item-top">
            <KeyValueView title="用户名" :value="getHideUserName(item.userName)"></KeyValueView>
            <KeyValueView title="注册时间" :value="$tiyBJTime(item.registertime)"></KeyValueView>
            <KeyValueView title="登录次数" :value="item.loginNumber"></KeyValueView>
            <KeyValueView title="加购次数" :value="item.addCartNumber"></KeyValueView>
            <KeyValueView title="付款订单数" :value="item.paidOrderNumber"></KeyValueView>
            <KeyValueView title="未付款订单数" :value="item.unpaidOrderNumber"></KeyValueView>
            <KeyValueView title="购物车总金额" :value="item.cartAmount"></KeyValueView>
          </div>
          <div class="item-top">
            <template v-if="!hasAuthority(tRole.ANALYSIS_6_201)">
              <KeyValueView title="来源" :value="item.source"></KeyValueView>
              <KeyValueView title="邀请码" :value="item.inviteCode"></KeyValueView>
              <KeyValueView title="补充邀请码" :value="item.externalInviteCode"></KeyValueView>
              <KeyValueView title="分配码" :value="item.assign"></KeyValueView>
              <KeyValueView title="邮箱">
                <Tooltip :content="item.email">
                  {{getHideUserName(item.email)}}
                </Tooltip>
              </KeyValueView>
              <KeyValueView title="独立站">
                <a :href="item.contactUrl" target="_blank">访问</a>
              </KeyValueView>
              <KeyValueView title="Instagram">
                <Tooltip :content="item.instagram">
                  {{getHideUserName(item.instagram)}}
                </Tooltip>
              </KeyValueView>
              <KeyValueView title="Facebook">
                <Tooltip :content="item.facebook">
                  {{getHideUserName(item.facebook)}}
                </Tooltip>
              </KeyValueView>
            </template>
          </div>
        </ListItem>
      </template>
    </List>

    <div style="float: right; margin-top: 20px;">
      <Page :total="tPage.total" :page-size="tPage.stepNumber" :current="tPage.currentPage" @on-change="changePage"
            @on-page-size-change="sizeChange" :page-size-opts=[40,60,80,120]
            show-sizer show-elevator/>
    </div>

  </div>

</template>

<!--javascript 代码-->
<script>
    import ICol from "../../../node_modules/view-design/src/components/grid/col";
    import tiyData from "./js/userDaily/userDaily_data";
    import {
        init,
        searchService
    } from "./js/userDaily/userDaily_funs";
    import KeyValueView from "../widgets/KeyValueView";
    import {isEmpty} from "../js/commonUtils";

    export default {
        components: {KeyValueView, ICol},
        data(){
            return {
                tRole: {//权限
                    ANALYSIS_6_101 : "ANALYSIS-6-101",
                  ANALYSIS_6_201: "ANALYSIS-6-201",
                },
                tParam : tiyData.tParams,
                tPage : tiyData.tPage,
                userDailyList : tiyData.tData.userDailyList,
                userDailyTable :tiyData.userDailyTable(this),
            }
        },
        computed: {
        },
        methods: {
            search(){
                searchService(this,tiyData);
            },
            changePage(page){
                tiyData.tPage.currentPage = page;
                searchService(this, tiyData);
            },
            sizeChange(p){
                tiyData.tPage.stepNumber = p;
                searchService(this, tiyData);
            },
            sortChanged(sort){
                tiyData.tPage.currentPage = 1;
                if(sort.order && sort.order != "normal"){
                    tiyData.tParams.searchParams.orderKey = sort.key;
                    tiyData.tParams.searchParams.orderType = sort.order;
                }
                searchService(this, tiyData);
            },
          getHideUserName(val) {
              if(isEmpty(val)) {
                return "";
              }
              return this.$tiyHideUsername(val);
          },
          hasAuthority(code) {
              return this.$authority(code);
          }
        },
        created(){
            init(tiyData);
        }
    }
</script>

<!--css样式-->
<style scoped lang="less">
@import  (once,optional)  "../css/base.less";

  .table_css {
    margin-top: 20px;
    margin-bottom: 20px;
  }

  .tiy_key {
    color: #9e9e9e;
    min-width: 90px;
    display: inline-block;
    text-align: right;
    padding-right: 0.5rem;
  }
.data-list {
  margin: 1rem 0rem;
  line-height: 25px;
  .list-item {
    .flex-colum-wrap;
    justify-items: left;
    align-items: start;
    .item-checkbox {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      vertical-align: top;
    }
    .item-img {
      width: 130px;
      text-align: center;
      display: inline-block;
    }
    .item-top{
      width: 100%;
      margin-bottom: 5px;
      .flex-row-wrap;
      justify-content: left;
    }
    .item-content {
      margin-bottom: 35px;
      text-align: left;
    }
    .item-bottom{
      //position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      display: block;
      //padding: 0 1rem 0.5rem 0;
      text-align: right;
      button {
        margin-left: 0.5rem;
      }
    }
  }
}
</style>
